package com.hxl.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//1.制作通知类，在类中定义一个方法用于完成共性功能
@Component
@Aspect
public class AOPAdvice {

    @Pointcut("execution(* *..*.*(..))")
    public void pt(){}
    @Before(value = "pt()")
    public void before()
    {


        System.out.println("before 在原始方法运行前运行...");

        //int i = 1/0;
    }

    public void after()
    {
        System.out.println("在原始方法运行后运行");
    }
    @AfterReturning(value = "pt()",returning = "ret")
    public void afterReturning(Object ret)
    {
        System.out.println("方法正常运行后执行");
        System.out.println(ret);
    }
    @AfterThrowing(value = "pt()",throwing = "t")
    public void afterThrowing(Throwable t)
    {
        System.out.println("原始方法抛异常后执行..."+t.getMessage());
    }

    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around 前置运行");
        Object res = pjp.proceed();
        System.out.println("around 后置运行");
        return res;
    }
}
